-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only reindex documents if declarations are being modified #2942
Only reindex documents if declarations are being modified #2942
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
41cc250
to
826bd1a
Compare
c103d7c
to
ea92bc7
Compare
2251c9d
to
e5b8c20
Compare
ea92bc7
to
f299a65
Compare
e5b8c20
to
41fc7d4
Compare
f299a65
to
6fa7091
Compare
41fc7d4
to
d03faf8
Compare
6fa7091
to
bfdeee1
Compare
bfdeee1
to
9814d66
Compare
d03faf8
to
cf1235e
Compare
9814d66
to
5f29c15
Compare
Just thinking out loud, but might a possible alternate approach be:
Since it's not dealing with the AST it would be faster, but it may result in more unnecessary re-indexing. Also it wouldn't correctly handle multi-line declarations. |
The issue is that this would be quite error prone. We'd be essentially trying to parse a subset of Ruby with regexes. Imagine cases like these do_something(class: "")
my_object.end
{ def: 123 }
include = 123 And most of the bugs would be silent because the LSP would simply just not reindex when it's suppose to, which would make them hard to detect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the early iterations, it might be useful to have some logging to indicate when indexing is being skipped.
5f29c15
to
34510e6
Compare
Good idea, but I did the opposite. Showing when we detect that a reindex is needed instead. |
34510e6
to
5cb18b5
Compare
Merge activity
|
Motivation
This PR tries to limit the amount of times we pay the price of reindexing the current document being modified by analyzing the context behind the last edit made to it.
Implementation
The idea of this approach is to remember the position of the last edit made to a document and the nature of the edit (insert, replace or delete).
Then, depending on the type of edit and what nodes exist under the position where the edit was made, we decide if reindexing is relevant or not.
To determine that, we look at the node under the cursor and, if it matches a node we use for indexing in the
DeclarationListener
, then we consider that we need to reindex.It's not perfect, so let me know if you have other ideas on how to determine this in a way that is:
Necessarily in this order because the whole point is to reduce the performance impact of having to reindex. If detecting whether we need to do it or not is equally as slow, then there's no point in doing it.
Automated Tests
Added some tests, but we should probably add more.